package com.ysh.controller;

import com.ysh.bean.Student;
import com.ysh.service.StudentService;
import com.ysh.service.impl.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/*
    控制层测试类
 */
public class StudentCotroller {
    // 创建业务层对象
    StudentService studentService = new StudentServiceImpl();

    // 查询全部功能测试
    @Test
    public void selectAll() {
        List<Student> list = new ArrayList<>();
        list = studentService.selectAll();
        for (Student student : list) {
            System.out.println(student);
        }

    }

    // 根据id进行查询
    @Test
    public void selectById() {
        // 调用service层获取到查询到的结果并封装好的Student对象
        Student stu = studentService.selectById(1);
        System.out.println(stu);
    }

    // 新增学生信息
    @Test
    public void insert() {
        Student stu = new Student(5, "杨幂", 18);
        Integer result = studentService.insert(stu);
        if (result != 0) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }

    // 修改学生信息
    @Test
    public void update() {
        Student stu = new Student(3, "高圆圆", 41);
        Integer update = studentService.update(stu);
        if (update != 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
    }

    // 删除学生信息
    @Test
    public void delete() {
        Integer delete = studentService.delete(3);
        if (delete != 0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }

    }
}
